package com.dm0858.bianmin.mine.tools;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import androidx.appcompat.app.AlertDialog;

import com.dm0858.bianmin.R;


/**
 * @description 权限弹窗工具类
 * @author 迪迪丶Sir
 * @e-mail asd969709719@qq.com
 * @since 2020-03-16
 **/
public class DialogUtils {


    public static void showPermissionManagerDialog(final Context context, String str) {
        new AlertDialog.Builder(context).setTitle("获取" + str + "权限被禁用")
                .setMessage("请在 设置-应用管理-" + context.getString(R.string.app_name) + "-权限管理 (将" + str + "权限打开)")
                .setNegativeButton("取消", null)
                .setPositiveButton("去设置", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        intent.setData(Uri.parse("package:" + context.getPackageName()));
                        context.startActivity(intent);
                    }
                })
                .show();
    }

    /**
     * @description 显示提示框
     * @author 迪迪丶Sir
     * @e-mail asd969709719@qq.com
     * @since 2020-04-16
     **/
    public static void showTipDialog(final Context context, String title, String message, onClickListener listener) {
        new AlertDialog
                .Builder(context)
                .setTitle(title)
                .setMessage(message)
                .setOnCancelListener(dialogInterface -> { listener.cancelClick(); })
                .setNegativeButton("取消", (dialogInterface, i) -> { listener.negativeClick(); })
                .setPositiveButton("确定", (dialogInterface, i) -> { listener.positiveClick(); })
                .show();
    }

    public interface onClickListener extends DialogInterface.OnClickListener {

        void negativeClick();

        void positiveClick();

        void cancelClick();
    }

}
